<?php
namespace app\api\controller;

use app\api\model\Menus as ModelMenus;

class Menus 
{
    public function __construct()
    {
        $this->Menus = new ModelMenus();
    }
    public function index()
    {
        $role = request()->param('role');
        return json(ModelMenus::getJsonMenus($role));
    }
    public function test(){
        $role = request()->param('role');
        return json(ModelMenus::getJsonMenus($role));
    }
    protected function setMenu($item, $index, $parent_index = ''){
        $m = new ModelMenus();
        if(!empty($parent_index)){
            $item['index'] = "$parent_index-$index";
            $item['parent'] = $parent_index;
        }else{
            $item['index'] = $index;
        }
        if($item['is_sub']){
            foreach($item['menus'] as $child_index => $child_item){
                $this->setMenu($child_item, $child_index+1, $item['index']);
            }
        }
        $m->save($item);
    }
    protected function setToken(){
        
    }
}
